
from PIL import Image
from PIL import ImageDraw
import numpy as np
class pic:
    def __init__(self,path):
        self.image = Image.open(path)
        
    def image_cut(self):
        # 图片路径，相对路径
        #image_path = 'H:\\挑战杯\\mak-HL2A\\CCD\\21400\\FCCD\\21400\\jpg\\00015.jpg'
        # 读取图片
        #image = Image.open(image_path)
        draw = ImageDraw.Draw(self.image)
        draw.rectangle(((150,30),(600,480)), outline='white')
        #image = image.crop((100,30,550,480))
        # 输出图片维度
        print("image_shape: ", self.image.size)
        # 显示图片
        self.image.show()

    def image2gray(self):
        r, g, b = self.image.split()
        r = np.asarray(r)
        g = np.asarray(g)
        b = np.asarray(b)

        rr = 0.3*r
        gg = 0.59*g
        bb = 0.11*b

        img = rr + gg + bb

        img = Image.fromarray(img)
        img.show()



if __name__ == '__main__':
    picture = pic('H:\\挑战杯\\mak-HL2A\\CCD\\21400\\FCCD\\21400\\jpg\\00018.jpg')
    picture.image2gray()